﻿namespace EyeOpen.ModularDemo.Mvc
{
	using System.Web.Hosting;
	using System.Web.Mvc;
	using System.Web.Routing;

	using EyeOpen.Mvc;
	using EyeOpen.Security.Data;
	using EyeOpen.Security.Mvc;
	using EyeOpen.Web.Hosting;
	using EyeOpen.Web.Mvc.Modules;

	public class DemoHttpModule : HttpModule
	{
		protected override void RegisterCustomRoutes(RouteCollection routes)
		{
			routes
				.MapRoute(
					"Default",
					"{controller}/{action}/{id}",
					new { controller = "FrontEnd", action = "Index", id = UrlParameter.Optional });
		}

		protected override void Initialize()
		{
			DependencyResolver
				.SetResolver(new SecurityDependencyResolver());

			HostingEnvironment
				.RegisterVirtualPathProvider(new EmbeddedVirtualPathProvider(new DemoVirtualPathInitializer()));

			new DatabaseCreateAndPopulate()
				.Create(DependencyResolver.Current.GetService<ISecurityUnitOfWork>());
		}
	}
}